package org.cug.service.impl;

import jakarta.servlet.http.HttpServletRequest;
import org.cug.mapper.UndergraduateInstructionMapper;
import org.cug.mapper.UserMapper;
import org.cug.pojo.UndergraduateInstruction;
import org.cug.pojo.User;
import org.cug.service.UndergraduateInstructionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UndergraduateInstructionServiceimpl implements UndergraduateInstructionService {
    @Autowired
    private UndergraduateInstructionMapper UndergraduateInstructionMapper;
    @Autowired
    private HttpServletRequest httpServletRequest;
    @Autowired
    private UserMapper userMapper;
    @Override
    public void add(UndergraduateInstruction undergraduate) {
        UndergraduateInstructionMapper.insert(undergraduate);
    }

    @Override
    public void delete(List<Integer> ids) {
        UndergraduateInstructionMapper.delete(ids);
    }

    @Override
    public UndergraduateInstruction selectid(Integer id) {
        UndergraduateInstruction undergraduate=UndergraduateInstructionMapper.selectid(id);
        return undergraduate;
    }

    @Override
    public void alterbyid(UndergraduateInstruction undergraduate) {
        UndergraduateInstructionMapper.update(undergraduate);
    }

    @Override
    public List<UndergraduateInstruction> list(Integer id, Short semester) {
        User user =userMapper.getrole(id);
        List<Integer> ids=new ArrayList<>();
        if(user.getRole().equals("1")){
            ids.add(id);
        }
        else if(user.getRole().equals("2")){
            ids = userMapper.getusers(user.getDepartment());
        }else if(user.getRole().equals("3")){
            ids = userMapper.getuserscol(user.getCollege());
        }else {
            List<UndergraduateInstruction> undergraduate=UndergraduateInstructionMapper.listall(semester);
            return undergraduate;
        }
        List<UndergraduateInstruction> undergraduate=UndergraduateInstructionMapper.list(ids,semester);
        return undergraduate;
    }
}
